﻿using NHibernate.Cfg;
using NHibernate.Dialect;
using NHibernate.Driver;
using NHibernate.Bytecode;
using NHibernate.Connection;
using InnovTech.Data.NHibernate.SQLiteUtil;

namespace InnovTech.Data.NHibernate
{
    public static class ConfigurationBuilder
    {
        public static Configuration GetMsSqlServerConfiguration(string userName, string pswd, string sqlServerName, string dbName, bool encrypt, bool UseWindowAuthentification)
        {
            Configuration config = new Configuration().SetProperty(Environment.ReleaseConnections, "on_close").
                                                       SetProperty(Environment.Dialect, typeof(MsSql2005Dialect).AssemblyQualifiedName).
                                                       SetProperty(Environment.ConnectionDriver, typeof(SqlClientDriver).AssemblyQualifiedName).
                                                       SetProperty(Environment.ConnectionString,
                                                                   string.Format(@"User Id={0}; Password={1}; Initial Catalog={2}; Data Source={3}; Encrypt={4}; Integrated Security={5};",
                                                                                 userName, pswd, dbName, sqlServerName, encrypt, UseWindowAuthentification)).
                                                       SetProperty(Environment.ProxyFactoryFactoryClass, typeof(DefaultProxyFactoryFactory).AssemblyQualifiedName).
                                                       SetProperty(Environment.ConnectionProvider, typeof(DriverConnectionProvider).AssemblyQualifiedName).
                                                       SetProperty(Environment.ShowSql, "true");
            return config;
        }
        public static Configuration GetMsSqlCeConfiguration(string filePath, bool encrypt, string password)
        {
            Configuration config = new Configuration().SetProperty(Environment.ReleaseConnections, "on_close").
                                                       SetProperty(Environment.Dialect, typeof(MsSqlCeDialect).AssemblyQualifiedName).
                                                       SetProperty(Environment.ConnectionDriver, typeof(SqlServerCeDriver).AssemblyQualifiedName).
                                                       SetProperty(Environment.ConnectionString, string.Format(@"Data Source={0}; File Mode=Exclusive; Encrypt={1}; Password={2};", filePath, encrypt, password)).
                                                       SetProperty(Environment.ProxyFactoryFactoryClass, typeof(DefaultProxyFactoryFactory).AssemblyQualifiedName).
                                                       SetProperty(Environment.ConnectionProvider, typeof(DriverConnectionProvider).AssemblyQualifiedName).
                                                       SetProperty(Environment.ShowSql, "true");
            return config;
        }


        public static Configuration GetSQLiteInMemoryConfiguration()
        {
            Configuration config = new Configuration().SetProperty(Environment.ReleaseConnections, "on_close").
                                                       SetProperty(Environment.Dialect, typeof(SQLiteDialect).AssemblyQualifiedName).
                                                       SetProperty(Environment.ConnectionDriver, typeof(SQLite20Driver).AssemblyQualifiedName).
                                                       SetProperty(Environment.ConnectionString, "data source=:memory:;Version=3;New=True;").
                                                       SetProperty(Environment.ProxyFactoryFactoryClass, typeof(DefaultProxyFactoryFactory).AssemblyQualifiedName).
                                                       SetProperty(Environment.ConnectionProvider, typeof(SQLiteInMemoryConnectionProvider).AssemblyQualifiedName).
                                                       SetProperty(Environment.ShowSql, "true");
            return config;
        }

    }



    


}
